/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package proyectoprogra3;
 

import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.LinkedList;
import javax.swing.*;
/**
 * 
 * @author Cáceres Cristóbal
 */
public class PJRadioButton extends JPanel implements KeyListener,ActionListener{
   
    ButtonGroup grupo;
    JLabel lblTexto;
    private JTextField texto;
    JTextArea txtRapido;
    JButton bt;
    private JRadioButton boton;
    private JPanel pn;
    private JButton eliminar;
    
    int indice;
    
    LinkedList<JPanel> panel=new LinkedList<JPanel>();
   
    public PJRadioButton() {
        
        this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS)); 
        
         grupo = new ButtonGroup();
        //grupo.add(boton);
        //bt = new JButton("Agregar");
       // bt.setSize(30, 20);
        //this.setLayout(new GridLayout(1, 1));
        this.add(pn=new JPanel());
        panel.add(pn);
        //pn.setLayout(new BoxLayout(pn, BoxLayout.X_AXIS));
        pn.setLayout(new FlowLayout());
        pn.add(boton=new JRadioButton());
        grupo.add(boton);
        pn.add(texto=new JTextField(30));
        pn.add(eliminar=new JButton("x"));
        indice=0;
        //pn.add(bt=new JButton("Agregar"));
        this.repaint();
        //bt.addActionListener(this);
        texto.addKeyListener( this );
        
        eliminar.addActionListener(this);
       
    }
    
         

    public JTextField getTexto() {
        return texto;
    }
    
        

//    @Override
//    public void actionPerformed(ActionEvent e) {
//       if(e.getSource()==bt){
//           
//       this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS)); 
//       this.add(pn=new JPanel());
//       pn.setLayout(new BoxLayout(pn, BoxLayout.X_AXIS));
//         
//       JRadioButton boton=new JRadioButton();
//        
//       // grupo = new ButtonGroup();
//       // grupo.add(boton);
//        JTextField texto=new JTextField(15);
//        //bt = new JButton("Agregar");
//       // bt.setSize(30, 20);
//       // this.setLayout(new FlowLayout());
//        pn.add(boton);
//        pn.add(texto);
//        //this.add(bt);
//        
//           
//          
//       }
//    }

    @Override
    public void keyTyped(KeyEvent e) {
       
    }

    @Override
    public void keyPressed(KeyEvent e) {
        
            switch(e.getKeyCode()){
                case KeyEvent.VK_ENTER:
                  this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS)); 
       this.add(pn=new JPanel());
       panel.add(pn);
       this.revalidate();
       
      // pn.setLayout(new BoxLayout(pn, BoxLayout.X_AXIS));
        pn.setLayout(new FlowLayout()); 
       JRadioButton boton=new JRadioButton();
        grupo.add(boton);
       // grupo = new ButtonGroup();
       // grupo.add(boton);
        texto=new JTextField(30);
        eliminar=new JButton("x");
        indice+=1;
        //bt = new JButton("Agregar");
       // bt.setSize(30, 20);
       // this.setLayout(new FlowLayout());
        pn.add(boton);
        pn.add(texto);
        pn.add(eliminar);
        //this.add(bt);
       this.repaint();
            }
        
    }

    @Override
    public void keyReleased(KeyEvent e) {
       
    }

    @Override
    public void actionPerformed(ActionEvent e) {
      if(e.getSource()==eliminar){
         for(int i=0;i<panel.size();i++){
             
         }
      }
    }
    
    
}

